package cn.edu.neusoft.wuguangsheng.flowerimpression.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.Utils.TimeUtils;
import cn.edu.neusoft.wuguangsheng.flowerimpression.activity.FKnowInfoActivity;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.FKnowBean;

public class FKnowAdapter extends BaseAdapter<FKnowBean> {
    String times;

    public FKnowAdapter(Context context, List<FKnowBean> items, int layoutResource){
        super(context, items, layoutResource);
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder=(ViewHolder) holder;
        FKnowBean fKnowBean=items.get(position);
        final String updatetime = fKnowBean.getFknow_updatetime();
        final String title = fKnowBean.getFknow_title();
        final String browse = fKnowBean.getFknow_browse();
        final String id = fKnowBean.getFknow_id();
        final String content = fKnowBean.getFknow_content();
        final String pl_num = fKnowBean.getPl_num();
        final String sc_num = fKnowBean.getSc_num();
        final String type = fKnowBean.getFknow_typename();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date date = simpleDateFormat.parse(updatetime);
            times = TimeUtils.getTimeFormatText(date);
        }catch (Exception e){
            e.printStackTrace();
        }
        viewHolder.item_title.setText(title);
        viewHolder.item_time.setText(times);
        viewHolder.item_browse.setText(browse);
        viewHolder.fknowitem_pl.setText(pl_num);
        viewHolder.fknowitem_sc.setText(sc_num);
        viewHolder.fknowitem_leixing.setText(type);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, FKnowInfoActivity.class);
                intent.putExtra("fknow_id",id);
                context.startActivity(intent);
            }
        });
    }
}
